<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #result {
            width: 200px;
            height: 200px;
            border: 1px solid lightskyblue;
        }
    </style>
</head>

<body>
    <div>
        <button>发送请求</button>
        <div id="result"></div>
    </div>
    <script>
        const result = document.getElementById('result')
        const btn = document.querySelectorAll('button')[0]
        let xml = null
        btn.onclick = function () {
            if (xml) {
                xml.abort()
            }
            xml = new XMLHttpRequest()
            xml.open('get', 'http://127.0.0.1:8000/server', true)
            xml.send()
            xml.onreadystatechange = function () {
                if (xml.readyState === 4) {
                    if (xml.status === 200 && xml.status < 300) {
                        result.innerHTML = xml.response
                        xml = null
                    }
                }
            }
        }
    </script>
</body>

</html>